﻿namespace td.Core.Xml
{
    using System;
    using System.Xml;

    public class ToolButtonXml : IXmlStorage
    {

        public string GroupName { get; set; }
        public string PageName { get; set; }
        public string Caption { get; set; }
        public string smallImage { get; set; }
        public string largeImage { get; set; }
        public string ToolTip { get; set; }
        public string ShortCut { get; set; }
        public string Class { get; set; }
        public string assembly { get; set; }
        public string ShowInNavBar { get;set;}


        public ToolButtonXml()
        {
            this.GroupName = null;
            this.PageName = null;
            this.Caption = null;
            this.smallImage = null;
            this.largeImage = null;
            this.ToolTip = null;
            this.ShortCut = null;
            this.Class = null;
            ShowInNavBar = null;
        }

        public ToolButtonXml(string groupName, string pageName, string caption,string classname)
        {

            this.GroupName = groupName;
            this.PageName = pageName;
            this.Caption =caption;
            this.Class = classname;
        }

        public ToolButtonXml(string groupName, string pageName, string caption, string classname,string smallimage,string largeimage,string tooltip,string shortcut,string showInNavBar)
        {
            this.GroupName = groupName;
            this.PageName =pageName;
            this.Caption = caption;
            this.smallImage = smallimage;
            this.largeImage = largeimage;
            this.ToolTip = tooltip;
            this.ShortCut = shortcut;
            this.Class = classname;
            this.ShowInNavBar = showInNavBar;
        }

        public override bool Equals(object o)
        {
            if (o is ToolButtonXml)
            {
                ToolButtonXml xml = (ToolButtonXml)o;
                return (string.Equals(this.Class, xml.Class) && string.Equals(this.Caption, xml.Caption));
            }
            return false;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public void GetValueFromXml(XmlNode objectNode)
        {
            if ((objectNode != null) && objectNode.Name.ToLower().Equals("toolbutton"))
            {
                XmlAttributeCollection attributes = objectNode.Attributes;
                for (int i = 0; i < attributes.Count; i++)
                {
                    XmlAttribute attribute = attributes[i];
                    if (attribute.Name.ToLower().Equals("pagename"))
                    {
                        this.PageName = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("groupname"))
                    {
                        this.GroupName = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("caption"))
                    {
                        this.Caption = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("smallimage"))
                    {
                        this.smallImage = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("largeimage"))
                    {
                        this.largeImage = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("tooltip"))
                    {
                        this.ToolTip = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("shortcut"))
                    {
                        this.ShortCut = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("class"))
                    {
                        this.Class = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("showinnavbar"))
                    {
                        this.ShowInNavBar = attribute.Value;
                    }
                }
            }
        }

        public void SetValueToXml(XmlDocument xmldoc, XmlElement parentEle)
        {
            XmlElement newChild = xmldoc.CreateElement("ToolButton");
            newChild.SetAttribute("PageName", this.PageName);
            newChild.SetAttribute("GroupName", this.GroupName);
            newChild.SetAttribute("Caption", this.Caption);
            newChild.SetAttribute("smallImage", this.smallImage);
            newChild.SetAttribute("largeImage", this.largeImage);
            newChild.SetAttribute("ToolTip", this.ToolTip);
            newChild.SetAttribute("ShortCut", this.ShortCut);
            newChild.SetAttribute("Class", this.Class);
            newChild.SetAttribute("ShowInNavBar", this.ShowInNavBar);
            parentEle.AppendChild(newChild);
        }

        public override string ToString()
        {
            return ("[ToolButtonXml: " + this.Caption + "]");
        }

        
 

 
    
    }
}

